package com.black.pay.controller;

import com.black.pay.model.Message;
import com.black.pay.service.MessageService;
import com.black.pay.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/api/message")
@CrossOrigin
public class MessageController extends BaseController{
    @Autowired
    MessageService messageService;
    public R add(@Validated Message message, BindingResult result) {
        R r = validateParams(result);
        if (r != null) {
            return r;
        }
        message.setGmt(new Date());
        messageService.save(message);
        return R.ok();
    }
}
